package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyStockDistribution;
import com.ruoyi.pims.service.IRyStockDistributionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存分布Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/distribution")
public class RyStockDistributionController extends BaseController
{
    private String prefix = "pims/distribution";

    @Autowired
    private IRyStockDistributionService ryStockDistributionService;

    @RequiresPermissions("pims:distribution:view")
    @GetMapping()
    public String distribution()
    {
        return prefix + "/distribution";
    }

    /**
     * 查询库存分布列表
     */
    @RequiresPermissions("pims:distribution:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyStockDistribution ryStockDistribution)
    {
        startPage();
        List<RyStockDistribution> list = ryStockDistributionService.selectRyStockDistributionList(ryStockDistribution);
        return getDataTable(list);
    }

    /**
     * 导出库存分布列表
     */
    @RequiresPermissions("pims:distribution:export")
    @Log(title = "库存分布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyStockDistribution ryStockDistribution)
    {
        List<RyStockDistribution> list = ryStockDistributionService.selectRyStockDistributionList(ryStockDistribution);
        ExcelUtil<RyStockDistribution> util = new ExcelUtil<RyStockDistribution>(RyStockDistribution.class);
        return util.exportExcel(list, "库存分布数据");
    }

    /**
     * 新增库存分布
     */
    @RequiresPermissions("pims:distribution:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存分布
     */
    @RequiresPermissions("pims:distribution:add")
    @Log(title = "库存分布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyStockDistribution ryStockDistribution)
    {
        return toAjax(ryStockDistributionService.insertRyStockDistribution(ryStockDistribution));
    }

    /**
     * 修改库存分布
     */
    @RequiresPermissions("pims:distribution:edit")
    @GetMapping("/edit/{distributionId}")
    public String edit(@PathVariable("distributionId") Long distributionId, ModelMap mmap)
    {
        RyStockDistribution ryStockDistribution = ryStockDistributionService.selectRyStockDistributionByDistributionId(distributionId);
        mmap.put("ryStockDistribution", ryStockDistribution);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存分布
     */
    @RequiresPermissions("pims:distribution:edit")
    @Log(title = "库存分布", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyStockDistribution ryStockDistribution)
    {
        return toAjax(ryStockDistributionService.updateRyStockDistribution(ryStockDistribution));
    }

    /**
     * 删除库存分布
     */
    @RequiresPermissions("pims:distribution:remove")
    @Log(title = "库存分布", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryStockDistributionService.deleteRyStockDistributionByDistributionIds(ids));
    }
}
